<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 思考如何将list中的数据转化为最终输出的结果？？？
        const list = [
            {
                correctionTime: "2018-11-30",
                departmentName: "总裁办",
                formOfEmployment: 1,
                id: "604f764971f93f3ac8f365c2",
                mobile: "13800000002",
                password: "e10adc3949ba59abbe56e057f20f883e",
                staffPhoto: "http://q6cu3t6jv.bkt.clouddn.com/1063705989926227968?t=1616204161907",
                timeOfEntry: "2018-11-02",
                username: "管理员",
                workNumber: "9002",
            },
            {
                correctionTime: "2018-11-20",
                departmentName: "市场部",
                formOfEmployment: 1,
                id: "604f764971f93f3ac8f365c3",
                mobile: "13800000003",
                password: "e10adc3949ba59abbe56e057f20f883e",
                staffPhoto: "http://q6cu3t6jv.bkt.clouddn.com/1063705989926227968?t=1616204161907",
                timeOfEntry: "2018-11-04",
                username: "孙财",
                workNumber: "111",
            }
        ]

function formatData(list) {
        const mapInfo = {
                'id': '编号',
                'password': '密码',
                'mobile': '手机号',
                'username': '姓名',
                'timeOfEntry': '入职日期',
                'formOfEmployment': '聘用形式',
                'correctionTime': '转正日期',
                'workNumber': '工号',
                'departmentName': '部门',
                'staffPhoto': '头像地址'
            }

            // header = ['编号','密码','手机号','入职日期','聘用形式'] 用于表格的头部
            // 1.获取表头
            const one = list[0]  // 取数组中一个对象
            let headers = []
            if(one) {
                 console.log('Object.keys(one)',Object.keys(one));  // ['correctionTime','departmentName','id',...]
                 headers = Object.keys(one).map(enkey=>{  // 遍历数组 --》 correctionTime ，departmentName ， id... 
                    return mapInfo[enkey] // ['编号','密码','手机号',...]
                 })
                }
            // 2.将每一个对象，对象中的值存到一个数组中，将每个数组存储到大数组中
            const data = list.map(item=>{
                console.log('Object.values(item)',Object.values(item));
                return Object.values(item) // 得到对象中值返回的是数组 -- ['2018-11-30','市场部',1,..]
            })
            return {headers:headers,data:data}
        }
        const {headers,data} = formatData(list)
            // console.log(headers); // ['编号','密码','手机号','入职日期','聘用形式']
            // console.log(data);  // [['2018-11-30', '总裁办', 1,..],['2018-11-20', '市场部', 1,...]]
    </script>
</body>
</html>